//
//  SCNToolsViewController.swift
//  ShoucainuSwift
//
//  Created by 王家旭 on 2017/4/25.
//  Copyright © 2017年 Riluee. All rights reserved.
//

import UIKit

struct SCNToolSourceObj {
    var img: String
    var title: String
    var details: String
    var path: String
    
    init(img: String,title: String,details: String,path: String) {
        self.img = img
        self.title = title
        self.details = details
        self.path = path
        
    }
}

class SCNToolsViewController: SCNTableViewController {

    
    fileprivate let sourceDate = [SCNToolSourceObj(img: "icon_study_encourage", title: "收益计算", details: "一分钟帮您计算平台收益", path: "company/cal_income/pagesource/app"),SCNToolSourceObj(img: "icon_study_well_known", title: "身价计算", details: "一分钟帮您计算身价", path: "company/cal_status/pagesource/app"),SCNToolSourceObj(img: "icon_study_health", title: "存款利率计算", details: "一分钟帮您计算银行存款收益", path: "company/cal_tate/pagesource/app"),SCNToolSourceObj(img: "icon_study_joke", title: "民间贷款计算", details: "一分钟帮您计算民间借款收益", path: "company/cal_deposit/pagesource/app")]
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "工具"
        
        self.createTableView(view.frame, style: .plain, isRefreshNewData: false, isRefreshMoreData: false) { (table) in
            
            table.rowHeight = 60
            
            table.register(SCNToolsViewTableViewCell.classForCoder(), forCellReuseIdentifier: NSStringFromClass(SCNToolsViewTableViewCell.classForCoder()))
        }
        tableView.isHidden = false
        
    }
}

extension SCNToolsViewController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return sourceDate.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: NSStringFromClass(SCNToolsViewTableViewCell.classForCoder()), for: indexPath) as! SCNToolsViewTableViewCell
        
        let obj = sourceDate[indexPath.row]
        
        cell.iconImageView.image = UIImage(named: obj.img)
        cell.titleL.text = obj.title
        cell.detailL.text = obj.details
        
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        defer {
            tableView.deselectRow(at: indexPath, animated: true)
        }
        
        let url = String(format: "%@%@", SCNRequestAPI.H5API,sourceDate[indexPath.row].path)
        
        self.loadWeb(at: self, url: url, title: "")

    }
}
